package cn.tedu.vue_master.controller;

import cn.tedu.vue_master.pojo.sku.vo.SkuListItemVO;
import cn.tedu.vue_master.pojo.sku.vo.SkuStandardVO;
import cn.tedu.vue_master.restful.JsonResult;
import cn.tedu.vue_master.service.ISkuService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "sku管理")
@RequestMapping("/sku")
public class SkuController {

    @Autowired
    private ISkuService skuService;


    @ApiOperationSupport(order = 100)
    @ApiOperation("根据id获取sku详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "string", example = "SKU00001")
    @GetMapping("/{id}")
    public JsonResult<SkuStandardVO> getStandardVO(@PathVariable String id) {
        log.debug("开始处理【根据id查询sku详情】的请求，id={}", id);
        SkuStandardVO skuStandardVO = skuService.getStandardVO(id);
        return JsonResult.ok(skuStandardVO);
    }


    @ApiOperationSupport(order = 200)
    @ApiOperation("根据spuId获取sku列表")
    @ApiImplicitParam(name = "spuId", value = "spuId", required = true, dataType = "string", example = "SPU00001")
    @GetMapping("/listBySpuId/{spuId}")
    public JsonResult<List<SkuListItemVO>> listBySpuId(@PathVariable String spuId) {
        log.debug("开始处理【根据spuId查询sku列表】的请求，spuId={}", spuId);
        List<SkuListItemVO> skuList = skuService.listBySpuId(spuId);
        return JsonResult.ok(skuList);
    }
}
